#  1. 打开register.html
#  2. 填写主页面 页面信息
#  3. 填写注册A 页面信息
#  4. 填写注册B 页面信息
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

driver = webdriver.Firefox()
url = 'file:///C:/Users/TEACHER/Desktop/NSD2405/html/register.html'
driver.get(url)

driver.find_element(By.ID, 'user').send_keys('admin')
driver.find_element(By.ID, 'password').send_keys('123456')
driver.find_element(By.ID, 'tel').send_keys('18812345678')
driver.find_element(By.ID, 'email').send_keys('123@qq.com')

# 切换到iframe，页面A
# 可以提供frame的id，name，元素对象
driver.switch_to.frame('idframe1') # 通过id切换
sleep(3)
driver.find_element(By.ID, 'userA').send_keys('admin')
driver.find_element(By.ID, 'passwordA').send_keys('123456')
driver.find_element(By.ID, 'telA').send_keys('18812345678')
driver.find_element(By.ID, 'emailA').send_keys('123@qq.com')
# 切换回主页面
driver.switch_to.default_content()
# 切换到B 页面
# driver.switch_to.frame('myframe2') # 通过name切换
element = driver.find_element(By.CSS_SELECTOR, '[src="registerB.html"]')
driver.switch_to.frame(element) # 通过元素对象切换

sleep(3)
driver.find_element(By.ID, 'userB').send_keys('admin')
driver.find_element(By.ID, 'passwordB').send_keys('123456')
driver.find_element(By.ID, 'telB').send_keys('18812345678')
driver.find_element(By.ID, 'emailB').send_keys('123@qq.com')

sleep(3)
driver.quit()


